package com.xuecheng.content.api;

import com.xuecheng.base.model.RestResponse;
import com.xuecheng.content.model.dto.BindMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.model.po.Teachplan;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("课程计划接口")
@RestController
@RequestMapping("/teachplan")
public class TeachplanController {
    @Autowired
    TeachplanService teachplanService;

    @ApiOperation("根据id查询成计划")
    @GetMapping("/{courseId}/tree-nodes")
    public List<TeachplanDto> queryAllTeachplansByCourseId(@PathVariable Long courseId){
        return teachplanService.queryAllTeachplansByCourseId(courseId);
    }

    @ApiOperation("新增或修改课程计划")
    @PostMapping
    public Teachplan saveTeachplan(@RequestBody SaveTeachplanDto dto){
        return teachplanService.saveTeachplan(dto);
    }

    @ApiOperation("课程计划上移")
    @PostMapping("/moveup/{id}")
    public void moveUp(@PathVariable Long id){
        teachplanService.moveUp(id);
    }

    @ApiOperation("课程计划下移")
    @PostMapping("/movedown/{id}")
    public void movedown(@PathVariable Long id){
        teachplanService.moveDown(id);
    }

    @ApiOperation("删除课程计划")
    @DeleteMapping("/{id}")
    public void deleteTeachplan(@PathVariable Long id){
        teachplanService.deleteTeachplan(id);
    }

    @ApiOperation("课程计划绑定视频")
    @PostMapping("/association/media")
    public RestResponse<Boolean> bindMedia(@RequestBody BindMediaDto dto){
        Long companyId = 1232141425L;
        return teachplanService.bindMedia(companyId,dto);
    }

    @ApiOperation("课程计划解绑视频")
    @DeleteMapping("/association/media/{teachplanId}/{mediaId}")
    public RestResponse<Boolean> unbindMedia(@PathVariable("teachplanId")Long teachplanId,
                                             @PathVariable("mediaId")Long mediaId){
        Long companyId = 1232141425L;
        return teachplanService.unbindMedia(companyId,teachplanId,mediaId);
    }

    @ApiOperation("根据课程计划id查询课程计划")
    @GetMapping("/{id}")
    public Teachplan getById(@PathVariable Long id){
        return teachplanService.getById(id);
    }
}
